package com.yyfax.ph.personal.authority.jpush;

import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yyfax.ph.base.YJPH;

import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

/**
* M层：绑定\解绑 极光推送
* @author ying_he
* @date 2017/3/8 12:40
*/
public class JPushModel extends Model {
    private static final String TAG = JPushModel.class.getSimpleName();

    @Override
    public void onNext(Object obj) {
        JPushResult result = cast(obj);
        EventAgent.post(result);
    }

    @Override
    public Observable getObservable(Object params, int functionalCode) {
        Service service = (Service) NetworkHelper.createService(Service.class);
        String token = YJPH.getInstance().getPreferenceManager().getLoginToken();
        return service.JPush(token, (JPushParams) params);
    }

    public interface Service {
        @POST("apply/push/bind")
        Observable<JPushModel.JPushResult> JPush(@Header("token") String token, @Body JPushModel.JPushParams params);
    }

    public static class JPushParams {
        String regId;
        String type;
    }

    public static class JPushResult extends BaseResultEntity {
    }
}
